import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { MallGoodsVO, MallGoodsForm, MallGoodsQuery } from '@/api/mall/mallGoods/types';

/**
 * 查询商品列表列表
 * @param query
 * @returns {*}
 */

export const listMallGoods = (query?: MallGoodsQuery): AxiosPromise<MallGoodsVO[]> => {
  return request({
    url: '/mall/mallGoods/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询商品列表详细
 * @param id
 */
export const getMallGoods = (id: string | number): AxiosPromise<MallGoodsVO> => {
  return request({
    url: '/mall/mallGoods/' + id,
    method: 'get'
  });
};

/**
 * 新增商品列表
 * @param data
 */
export const addMallGoods = (data: MallGoodsForm) => {
  return request({
    url: '/mall/mallGoods',
    method: 'post',
    data: data
  });
};

/**
 * 修改商品列表
 * @param data
 */
export const updateMallGoods = (data: MallGoodsForm) => {
  return request({
    url: '/mall/mallGoods',
    method: 'put',
    data: data
  });
};

/**
 * 删除商品列表
 * @param id
 */
export const delMallGoods = (id: string | number | Array<string | number>) => {
  return request({
    url: '/mall/mallGoods/' + id,
    method: 'delete'
  });
};
/**
 * 删除商品sku列表
 * @param id
 */
export const delGoodsSkuApi = (id: string | number | Array<string | number>) => {
  return request({
    url: '/mall/mallGoods/skus/' + id,
    method: 'delete'
  });
};
/**
 * 修改商品上下架
 * @param id
 * @param goodsStatus
 */
export const updateStatus = (id: number, goodsStatus: number) => {
  return request({
    url: `/mall/mallGoods/updateStatus/${id}/${goodsStatus}`,
    method: 'put'
  });
};
/**
 * 修改商品审核状态
 * @param id
 * @param goodsVerify
 */
export const updateVerify = (id: number, goodsVerify: number) => {
  return request({
    url: `/mall/mallGoods/updateVerify/${id}/${goodsVerify}`,
    method: 'put'
  });
};
/**
 * 推荐商家首页
 * @param id
 * @param isRecommend
 */
export const updateRecommend = (id: number, isRecommend: number) => {
  return request({
    url: `/mall/mallGoods/updateRecommend/${id}/${isRecommend}`,
    method: 'put'
  });
};
/**
 * 推荐主站首页
 * @param id
 * @param isMaster
 */
export const updateMaster = (id: number, isMaster: number) => {
  return request({
    url: `/mall/mallGoods/updateMaster/${id}/${isMaster}`,
    method: 'put'
  });
};
